import { OperatorEnum } from '@lib/shared/enums/commonEnum';
import { CustomerSearchTypeEnum } from '@lib/shared/enums/customerEnum';
import { FieldTypeEnum, FormDesignKeyEnum } from '@lib/shared/enums/formDesignEnum';

import { FilterFormItem } from '@/components/pure/crm-advance-filter/type';

import {
  addAccountPoolView,
  addBusinessView,
  addClueView,
  addContactView,
  addContractView,
  addCustomerView,
  addFollowPlanView,
  addFollowRecordView,
  addLeadPoolView,
  addPaymentPlanView,
  addQuotationView,
  deleteAccountPoolView,
  deleteBusinessView,
  deleteClueView,
  deleteContactView,
  deleteContractView,
  deleteCustomerView,
  deleteFollowPlanView,
  deleteFollowRecordView,
  deleteLeadPoolView,
  deletePaymentPlanView,
  deleteQuotationView,
  dragAccountPoolView,
  dragBusinessView,
  dragClueView,
  dragContactView,
  dragContractView,
  dragCustomerView,
  dragFollowPlanView,
  dragFollowRecordView,
  dragLeadPoolView,
  dragPaymentPlanView,
  dragQuotationView,
  enableAccountPoolView,
  enableBusinessView,
  enableClueView,
  enableContactView,
  enableContractView,
  enableCustomerView,
  enableFollowPlanView,
  enableFollowRecordView,
  enableLeadPoolView,
  enablePaymentPlanView,
  enableQuotationView,
  fixedAccountPoolView,
  fixedBusinessView,
  fixedClueView,
  fixedContactView,
  fixedContractView,
  fixedCustomerView,
  fixedFollowPlanView,
  fixedFollowRecordView,
  fixedLeadPoolView,
  fixedPaymentPlanView,
  fixedQuotationView,
  getAccountPoolViewDetail,
  getAccountPoolViewList,
  getBusinessViewDetail,
  getBusinessViewList,
  getClueViewDetail,
  getClueViewList,
  getContactViewDetail,
  getContactViewList,
  getContractViewDetail,
  getContractViewList,
  getCustomerViewDetail,
  getCustomerViewList,
  getFollowPlanViewDetail,
  getFollowPlanViewList,
  getFollowRecordViewDetail,
  getFollowRecordViewList,
  getLeadPoolViewDetail,
  getLeadPoolViewList,
  getPaymentPlanViewDetail,
  getPaymentPlanViewList,
  getQuotationViewDetail,
  getQuotationViewList,
  updateAccountPoolView,
  updateBusinessView,
  updateClueView,
  updateContactView,
  updateContractView,
  updateCustomerView,
  updateFollowPlanView,
  updateFollowRecordView,
  updateLeadPoolView,
  updatePaymentPlanView,
  updateQuotationView,
} from '@/api/modules';
import { TabType } from '@/hooks/useHiddenTab';
import useUserStore from '@/store/modules/user';

const userStore = useUserStore();

type ViewAction = 'list' | 'add' | 'update' | 'delete' | 'detail' | 'fixed' | 'enable' | 'drag';

export const viewApiMap: Record<ViewAction, Record<TabType, (...args: any[]) => Promise<any>>> = {
  list: {
    [FormDesignKeyEnum.CLUE]: getClueViewList,
    [FormDesignKeyEnum.CUSTOMER]: getCustomerViewList,
    [FormDesignKeyEnum.CONTACT]: getContactViewList,
    [FormDesignKeyEnum.BUSINESS]: getBusinessViewList,
    [FormDesignKeyEnum.CLUE_POOL]: getLeadPoolViewList,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: getAccountPoolViewList,
    [FormDesignKeyEnum.FOLLOW_PLAN]: getFollowPlanViewList,
    [FormDesignKeyEnum.FOLLOW_RECORD]: getFollowRecordViewList,
    [FormDesignKeyEnum.CONTRACT]: getContractViewList,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: getPaymentPlanViewList,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: getQuotationViewList,
  },
  add: {
    [FormDesignKeyEnum.CLUE]: addClueView,
    [FormDesignKeyEnum.CUSTOMER]: addCustomerView,
    [FormDesignKeyEnum.CONTACT]: addContactView,
    [FormDesignKeyEnum.BUSINESS]: addBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: addLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: addAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: addFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: addFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: addContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: addPaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: addQuotationView,
  },
  update: {
    [FormDesignKeyEnum.CLUE]: updateClueView,
    [FormDesignKeyEnum.CUSTOMER]: updateCustomerView,
    [FormDesignKeyEnum.CONTACT]: updateContactView,
    [FormDesignKeyEnum.BUSINESS]: updateBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: updateLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: updateAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: updateFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: updateFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: updateContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: updatePaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: updateQuotationView,
  },
  delete: {
    [FormDesignKeyEnum.CLUE]: deleteClueView,
    [FormDesignKeyEnum.CUSTOMER]: deleteCustomerView,
    [FormDesignKeyEnum.CONTACT]: deleteContactView,
    [FormDesignKeyEnum.BUSINESS]: deleteBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: deleteLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: deleteAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: deleteFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: deleteFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: deleteContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: deletePaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: deleteQuotationView,
  },
  detail: {
    [FormDesignKeyEnum.CLUE]: getClueViewDetail,
    [FormDesignKeyEnum.CUSTOMER]: getCustomerViewDetail,
    [FormDesignKeyEnum.CONTACT]: getContactViewDetail,
    [FormDesignKeyEnum.BUSINESS]: getBusinessViewDetail,
    [FormDesignKeyEnum.CLUE_POOL]: getLeadPoolViewDetail,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: getAccountPoolViewDetail,
    [FormDesignKeyEnum.FOLLOW_PLAN]: getFollowPlanViewDetail,
    [FormDesignKeyEnum.FOLLOW_RECORD]: getFollowRecordViewDetail,
    [FormDesignKeyEnum.CONTRACT]: getContractViewDetail,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: getPaymentPlanViewDetail,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: getQuotationViewDetail,
  },
  fixed: {
    [FormDesignKeyEnum.CLUE]: fixedClueView,
    [FormDesignKeyEnum.CUSTOMER]: fixedCustomerView,
    [FormDesignKeyEnum.CONTACT]: fixedContactView,
    [FormDesignKeyEnum.BUSINESS]: fixedBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: fixedLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: fixedAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: fixedFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: fixedFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: fixedContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: fixedPaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: fixedQuotationView,
  },
  enable: {
    [FormDesignKeyEnum.CLUE]: enableClueView,
    [FormDesignKeyEnum.CUSTOMER]: enableCustomerView,
    [FormDesignKeyEnum.CONTACT]: enableContactView,
    [FormDesignKeyEnum.BUSINESS]: enableBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: enableLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: enableAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: enableFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: enableFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: enableContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: enablePaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: enableQuotationView,
  },
  drag: {
    [FormDesignKeyEnum.CLUE]: dragClueView,
    [FormDesignKeyEnum.CUSTOMER]: dragCustomerView,
    [FormDesignKeyEnum.CONTACT]: dragContactView,
    [FormDesignKeyEnum.BUSINESS]: dragBusinessView,
    [FormDesignKeyEnum.CLUE_POOL]: dragLeadPoolView,
    [FormDesignKeyEnum.CUSTOMER_OPEN_SEA]: dragAccountPoolView,
    [FormDesignKeyEnum.FOLLOW_PLAN]: dragFollowPlanView,
    [FormDesignKeyEnum.FOLLOW_RECORD]: dragFollowRecordView,
    [FormDesignKeyEnum.CONTRACT]: dragContractView,
    [FormDesignKeyEnum.CONTRACT_PAYMENT]: dragPaymentPlanView,
    [FormDesignKeyEnum.OPPORTUNITY_QUOTATION]: dragQuotationView,
  },
};

export const internalConditionsMap: Record<string, FilterFormItem[]> = {
  [CustomerSearchTypeEnum.ALL]: [
    {
      dataIndex: 'createTime',
      type: FieldTypeEnum.TIME_RANGE_PICKER,
      operator: OperatorEnum.GT,
      value: 0,
    },
  ],
  [CustomerSearchTypeEnum.DEPARTMENT]: [
    {
      dataIndex: 'departmentId',
      type: FieldTypeEnum.TREE_SELECT,
      operator: OperatorEnum.IN,
      value: [userStore.userInfo.departmentId],
      containChildIds: [],
    },
  ],
  [CustomerSearchTypeEnum.SELF]: [
    {
      dataIndex: 'owner',
      type: FieldTypeEnum.MEMBER,
      operator: OperatorEnum.IN,
      value: [userStore.userInfo.id],
      selectedUserList: [{ id: userStore.userInfo.id, name: userStore.userInfo.name }],
    },
  ],
};

export default {};
